#include "imgprogressbar.h"
#include <QPainter>
#include "funcmgr.h"


ImgProgressBar::ImgProgressBar(QWidget *parent) : QProgressBar(parent)
{
    setMinimum(0);
    setMaximum(100);
    setValue(0);

    setAttribute(Qt::WA_TranslucentBackground);
}

void ImgProgressBar::paintEvent(QPaintEvent *)
{
    QPainter Painter(this);

    //绘制背景色
    QPainterPath pathBack;
    pathBack.setFillRule(Qt::WindingFill);
    pathBack.addRect(QRect(0, 0, this->width(), this->height()));
    Painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
    Painter.fillPath(pathBack, QBrush(QColor(48, 48, 52)));

    //绘制进度条
    QRect BarRect = QRect(0, 0, width(), height());
    const double NowPn = (double)(value()) / maximum();
    quint64 PnWidth = (quint64)(BarRect.width() * NowPn);
    QRect FillRect = BarRect.adjusted(0, 0, PnWidth - BarRect.width(), 0);
    QPixmap FillMap = QPixmap(":/Resources/Bar.png");
    Painter.drawPixmap(FillRect, FillMap);
}
